
##############################################################################
#
#	通过两次编译的方式将tmp.build 集成进来
#		目录
#		目标
#
#
##############################################################################


# 首先声明最先生成的目标
build :

obj-y :=
subdir-y :=
lib_static :=
lib_dynamic :=


# 包含目标目录Makefile
include Makefile

# 获取子目录并去掉 / 
__subdir-y	:= $(patsubst %/,%,$(filter %/, $(obj-y)))
subdir-y	+= $(__subdir-y)

# 获取源文件
objs-y   := $(filter-out %/, $(obj-y))

# 包含编译相关配置
include $(TOPDIR)/mk/config.mk
include $(TOPDIR)/mk/var.mk
include $(TOPDIR)/mk/common.mk
include $(TOPDIR)/mk/library.mk


$(warning objs is $(objs-y))
$(warning subdir is $(subdir-y))
$(warning subdir_objs is $(subdir_objs))


# 虚假目标: 必须是 include 下面
.PHONY : build $(subdir-y) tmp_build $(lib_static) $(lib_dynamic) $(program)


# 编译
build : $(subdir-y) tmp_build $(objs-y) $(lib_static) $(lib_dynamic) $(program) 

$(warning objs is $(objs-y))

# 子目录编译
$(subdir-y):
	@ # 删除老旧的 temp.build
	@ # rm -rf $@/temp.build
	@ # 强制使用 Makefile.build编译子目录 
	$(if $(KBUILD_VERBOSE:1=), @) make -C $@ -f $(TOPDIR)/mk/extapp.mk



tmp_build:
ifeq ($(subdir-y), )
	@ $(shell pwd) 
else
	@ # 将子目录的 tmp.build 合成一个
	for dir in $(subdir-y); do 	cat $$dir/tmp.build  >> tmp.build; done  
endif

